let metaEl;
metaEl = document.createElement('meta');
metaEl.setAttribute('name', 'viewport');
if (/Android (\d+\.\d+)/.test(navigator.userAgent)) {
  let version = parseFloat(RegExp.$1);
  if (version > 2.3) {
    let phoneScale = parseInt(window.screen.width) / 750;
    metaEl.setAttribute('content', 'width=750,minimum-scale=' + phoneScale + ',maximum-scale=' + phoneScale + ',target-densitydpi=device-dpi')
  } else {
    metaEl.setAttribute('content', 'width=750,target-densitydpi=device-dpi')
  }
} else {
  metaEl.setAttribute('content', 'width=750,user-scalable=no,target-densitydpi=device-dpi,minimal-ui')
}
document.documentElement.firstElementChild.appendChild(metaEl)

$(document).ready(function () {
  $('.remain-container .tab li').click(function () {
    $('.remain-container .tab li').removeClass('active')
    $(this.addClass('active'))
  })

  //取消or 預定开关
  $('.list-ty .yd').click(function () {
    if ($(this).hasClass('active')) {
      $(this).removeClass('active');
      $(this).text('预定')
    } else {
      $(this).addClass('active');
      $(this).text('取消')
    }

    let list = $('.list-ty .yd');
    let activeNum = 0;
    for (let i = 0; i < list.length; i++) {
      if (list.eq(i).hasClass('active')) {
        activeNum++
        $('.button').css('display', 'block')
        $('.list-ty').css('padding-bottom', '88px')
      }
    }
    if (activeNum === 0) {
      $('.button').css('display', 'none')
      $('.list-ty').css('padding-bottom', '0')
    }
  })

  //功能选择
  let $type = $('.pro-type>div');
  $type.click(function () {
    for (let i = 0; i < $type.length; i++) {
      $type.eq(i).removeClass('active')
    }
    $(this).toggleClass('active')
    $('.list-ty').css('display', 'none');
    $('.list-ty').eq($(this).index()).css('display', 'block');
  })

  $('.button').click(function () {
    getProjectName()
  })
  //日期选择
  let $datatype=$('.time .li');
  $datatype.on('click',function(){
    $datatype.removeClass('active')
    $(this).addClass('active')
  })
});



//获取项目名称
function getProjectName() {
  let label = []
  let list = $('.list-ty .yd');
  for (let i = 0; i < list.length; i++) {
    if (list.eq(i).hasClass('active')) {
      label.push(list.eq(i).parents('.make').prev().find('p:first-child').text())
    }
  }
  return label;
}

function setTime(val) {
  let countdown = 60;
  val.setAttribute("disabled", true);
  document.getElementById("tip").style.display = "block";
  let t = setInterval(function () {
    countdown--;
    document.getElementById("timeNum").innerHTML = countdown;
    if (countdown === 0) {
      val.removeAttribute("disabled");
      document.getElementById("tip").style.display = "none";
      clearInterval(t)
    }
  }, 1000);
}

function modify() {
  let button = document.getElementsByTagName("button")[0];
  if (button.value === "0") {
    button.innerHTML = "保存";
    button.value = 1;
    for (let i = 0; i < 4; i++) {
      document.getElementsByClassName("modifyInfo")[i].removeAttribute("disabled");
      document.getElementsByClassName("modifyInfo")[i].style.border = "thin solid #cccccc";
    }
  } else if (button.value === "1") {
    if (document.getElementById("labelTel").innerHTML === "" && document.getElementById("labelAge").innerHTML === "") {
      button.innerHTML = "修改";
      button.value = 0;
      for (let i = 0; i < 4; i++) {
        document.getElementsByClassName("modifyInfo")[i].setAttribute("disabled", true);
        document.getElementsByClassName("modifyInfo")[i].style.border = "none";
      }
    }

  }
}

function verifyTel() {
  let tel = document.getElementById("tel").value;
  if (!(/^1[34578]\d{9}$/.test(tel))) {
    document.getElementById("labelTel").innerHTML = "输入手机号码错误";
    return false;
  } else {
    document.getElementById("labelTel").innerHTML = "";
  }
}

function verifyAge() {
  let age = document.getElementById("age").value;
  if (!(/^[0-9]*[1-9][0-9]*$/.test(age))) {
    document.getElementById("labelAge").innerHTML = "输入年龄错误";
    return false;
  } else {
    document.getElementById("labelAge").innerHTML = "";
  }
}
